correct sort filter time option to use msecs.
authortsteven4 <tsteven4@gmail.com>
Thu, 11 Oct 2018 17:28:41 +0000 (11:28 -0600)
committertsteven4 <tsteven4@gmail.com>
Thu, 11 Oct 2018 17:28:41 +0000 (11:28 -0600)
reference/sortfilter_in.gpx [new file with mode: 0644]
reference/sortfilter_out.gpx [new file with mode: 0644]
sort.cc
testo.d/sort.test [new file with mode: 0644]

diff --git a/reference/sortfilter_in.gpx b/reference/sortfilter_in.gpx
new file mode 100644 (file)
index 0000000..2fb72ca
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gpx version="1.0" creator="tsteven4" xmlns="http://www.topografix.com/GPX/1/0">
+  <wpt lat="48.8583701" lon="2.2922926">
+    <time>2018-07-06T05:04:03.750Z</time>
+  </wpt>
+  <wpt lat="48.8583701" lon="2.2922926">
+    <time>2018-07-06T05:04:03.250Z</time>
+  </wpt>
+  <wpt lat="48.8583701" lon="2.2922926">
+    <time>2018-07-07T05:04:03.750Z</time>
+  </wpt>
+  <wpt lat="48.8583701" lon="2.2922926">
+    <time>2018-07-05T05:04:03.750Z</time>
+  </wpt>
+</gpx>
diff --git a/reference/sortfilter_out.gpx b/reference/sortfilter_out.gpx
new file mode 100644 (file)
index 0000000..2feb73b
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gpx version="1.0" creator="GPSBabel - http://www.gpsbabel.org" xmlns="http://www.topografix.com/GPX/1/0">
+  <time>1970-01-01T00:00:00Z</time>
+  <bounds minlat="48.858370100" minlon="2.292292600" maxlat="48.858370100" maxlon="2.292292600"/>
+  <wpt lat="48.858370100" lon="2.292292600">
+    <time>2018-07-05T05:04:03.750Z</time>
+    <name>WPT004</name>
+    <cmt>WPT004</cmt>
+    <desc>WPT004</desc>
+  </wpt>
+  <wpt lat="48.858370100" lon="2.292292600">
+    <time>2018-07-06T05:04:03.250Z</time>
+    <name>WPT002</name>
+    <cmt>WPT002</cmt>
+    <desc>WPT002</desc>
+  </wpt>
+  <wpt lat="48.858370100" lon="2.292292600">
+    <time>2018-07-06T05:04:03.750Z</time>
+    <name>WPT001</name>
+    <cmt>WPT001</cmt>
+    <desc>WPT001</desc>
+  </wpt>
+  <wpt lat="48.858370100" lon="2.292292600">
+    <time>2018-07-07T05:04:03.750Z</time>
+    <name>WPT003</name>
+    <cmt>WPT003</cmt>
+    <desc>WPT003</desc>
+  </wpt>
+</gpx>
diff --git a/sort.cc b/sort.cc
index a50be2c73644ca074276070110c3a773a116676b..8c096d3452d89eefcdf107ffc1fb49f633193a40 100644 (file)
--- a/sort.cc
+++ b/sort.cc
 
 #if FILTERS_ENABLED
 
+template <class T>
+inline int sgn(T v) {
+// Returns 1 if v > 0, -1 if v < 0, and 0 if v is zero
+  return (v > T(0)) - (v < T(0));
+}
+
 int SortFilter::sort_comp(const queue* a, const queue* b)
 {
   const Waypoint* x1 = reinterpret_cast<const Waypoint *>(a);
@@ -38,7 +44,7 @@ int SortFilter::sort_comp(const queue* a, const queue* b)
   case sm_description:
     return x1->description.compare(x2->description);
   case sm_time:
-    return x1->GetCreationTime().toTime_t() - x2->GetCreationTime().toTime_t();
+    return sgn(x2->GetCreationTime().msecsTo(x1->GetCreationTime()));
   default:
     abort();
     return 0; /* Internal caller error. */
diff --git a/testo.d/sort.test b/testo.d/sort.test
new file mode 100644 (file)
index 0000000..cc00b34
--- /dev/null
@@ -0,0 +1,9 @@
+#
+# sort filter tests
+#
+
+rm -f ${TMPDIR}/sortfilter*
+
+gpsbabel -i gpx -f ${REFERENCE}/sortfilter_in.gpx -x sort,time -o gpx -F ${TMPDIR}/sortfilter_out.gpx
+compare ${REFERENCE}/sortfilter_out.gpx ${TMPDIR}/sortfilter_out.gpx
+